//
//  MKNewsSystemCell.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/10.
//  Copyright © 2017年 cc.moko. All rights reserved.
//

import UIKit

class MKNewsSystemCell: MKBaseTableViewCell {

    var icon:UIImageView!
    var count:UILabel!
    var tip:UILabel!
    var arrow:UIImageView!
    var line:UIView!
    var lineHiden:Bool!
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.makeUI()
    }
    func makeUI() -> Void {
        self.icon = UIImageView.init()
        self.contentView.addSubview(self.icon)
        
        self.tip = UILabel.label(fontSize: 16, textColor: UIColorFromRGB(rgbValue: 0x333333, A: 1))
        self.contentView.addSubview(self.tip)
        
        self.count = UILabel.label(fontSize: 10, textColor: UIColor.white)
        self.count.textAlignment = .center
        self.count.backgroundColor = UIColorFromRGB(rgbValue: 0xff0051, A: 1)
        self.contentView.addSubview(self.count)
        
        self.arrow = UIImageView.init()
        self.arrow.image = UIImage.init(named: "newMe_enterArrow")
        self.contentView.addSubview(self.arrow)
        
        self.line = UIView.init()
        self.line.backgroundColor = UIColorFromRGB(rgbValue: 0xe5e5e5, A: 1)
        self.contentView.addSubview(self.line)
    }
    
    func config(icon:String,count:Int,tip:String,lineHiden:Bool) -> Void {
        
        self.icon.image = UIImage.init(named: icon)
        self.tip.text = tip
        self.count.isHidden = count <= 0
        if(count > 99){
          self.count.text = "N"
        }else{
            self.count.text = String.init(stringInterpolationSegment: count)
        }
        self.lineHiden = lineHiden
        self.setNeedsLayout()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.icon.frame = CGRect.init(x: 10, y: (self.contentView.height - 25) * 0.5, width: 25, height: 25)
        
        self.tip.sizeToFit()
        self.tip.frame = CGRect.init(x: self.icon.right + 10, y: (self.contentView.height - self.tip.height) * 0.5, width: self.tip.width, height: self.tip.height)
        
        self.count.frame = CGRect.init(x: self.icon.right - 7.5, y: self.icon.top - 7.5, width: 15, height: 15)
        self.count.layer.cornerRadius = 7.5
        self.count.clipsToBounds = true
        
        self.arrow.frame = CGRect.init(x: self.contentView.width - 10 - 8.5, y: (self.contentView.height - 16) * 0.5, width: 8.5, height: 16)
        if(self.lineHiden){
            self.line.frame = CGRect.zero
        }else{
          self.line.frame = CGRect.init(x: self.tip.left, y: self.contentView.height - 0.5, width: self.contentView.width - self.tip.left, height: 0.5)
        }
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
